package com.raccoonagents.tools.cascet2d.model;

import java.io.File;
import java.io.IOException;

import com.raccoonagents.tools.cascet2d.model.exceptions.UnavailableException;
import com.raccoonagents.tools.cascet2d.util.FWLogger;
import com.raccoonagents.tools.cascet2d.util.GraphicUtil;

public class ImageResource extends AbstractResource{
	
	private Integer texture = null;
	/**
	 * 
	 * @param image
	 */
	public ImageResource(final File image){
		super(image);
	}
	/**
	 * loads the image resource from disk.
	 * @throws IOException
	 */
	public void load() throws IOException{
			
		if(GraphicUtil.IMAGE_TYPE.getTypeFromName(handle.getName()) == null){
			throw new IOException("image type is not supported : " + handle.getAbsolutePath());
		}
		FWLogger.info("loading : " + handle.getAbsolutePath());
		texture = GraphicUtil.loadTexture(handle.getAbsolutePath());
	}
	
	public int getTexture() throws UnavailableException{
		if(texture == null){
			throw new UnavailableException("image was not loaded.");
		}
		return texture;
	}
}
